package com.dtwave.wechat.service.provider.common.utils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class Conversion {

	 /**
     * 将上传的录音转为mp3格式
     * @param webroot 项目的根目录
     * @param sourcePath 文件的相对地址
     */
	
    public static void ToMp3(String localPath, String targetFilePath){
        String command = "/usr/local/ffmpeg  -i "+localPath+" "+targetFilePath;
        Runtime runtime = Runtime.getRuntime();
        try {
            Process proc = runtime.exec(command);
            InputStream stderr = proc.getErrorStream();
            InputStreamReader isr = new InputStreamReader(stderr);
            BufferedReader br = new BufferedReader(isr);
            String line = null;
            StringBuffer sb = new StringBuffer();
            while((line = br.readLine()) != null){
                sb.append(line);
            }
            int exitVal = proc.waitFor();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            //log.debug("ffmpeg exec cmd Exception " + e.toString());
        }
    }
 
    public static void main(String[] args) {
        ToMp3("/Users/liuwenxiang/Desktop/681.amr","/Users/liuwenxiang/Desktop/ooo.mp3");
    }
}
